package com.sojson.controller.po;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sojson.entity.po.Deposit;
import com.sojson.entity.vo.MemberVo;
import com.sojson.result.Result;
import com.sojson.service.DepositService;
import com.sojson.service.MemberService;
import com.sojson.util.token.TokenUtil;

import io.swagger.annotations.Api;

/**
 * 诚意金信息表控制器
 * 
 * @author liu
 * @date 2021-05-08
 */
@Api(tags = "诚意金信息表管理")
@RestController
@RequestMapping("/deposit")
public class DepositController {

    @Autowired
    private MemberService memberService;
    @Autowired
    private DepositService depositService;

    /**
     * 单条插入
     * 
     * @param deposit
     * @return
     */
    // @PostMapping("/insert")
    public Object insert(@RequestBody Deposit deposit) {
        return Result.success(depositService.insert(deposit));
    }

    /**
     * 批量插入
     * 
     * @param deposit
     * @return
     */
    // @PostMapping("/insertList")
    public Object insertList(@RequestBody Deposit deposit) {
        return Result.success(depositService.insertList(deposit));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param deposit
     * @return
     */
    // @DeleteMapping("/deleteByDto")
    public Object deleteByDto(@RequestBody Deposit deposit) {
        return Result.success(depositService.deleteByDto(deposit));
    }

    /**
     * 统计全部数量
     * 
     * @return
     */
    // @GetMapping("/countAll")
    public Object countAll() {
        return Result.success(depositService.countAll());
    }

    /**
     * 查询所有
     * 
     * @return
     */
    // @GetMapping("/findAll")
    public Object findAll() {
        return Result.success(depositService.findAll());
    }

    /**
     * 根据对象统计数量
     * 
     * @param deposit
     * @return
     */
    // @GetMapping("/countByDto")
    public Object countByDto(Deposit deposit) {
        return Result.success(depositService.countByDto(deposit));
    }

    /**
     * 根据对象查询
     * 
     * @param deposit
     * @return
     */
    // @GetMapping("/findByDto")
    public Object findByDto(Deposit deposit) {
        return Result.success(depositService.findByDto(deposit));
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     */
    // @DeleteMapping("/deleteById")
    public Object deleteById(Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(depositService.deleteById(id));
    }

    /**
     * 通过id列表删除(物理删除)
     * 
     * @param ids
     * @return
     */
    // @DeleteMapping("/deleteByIdList")
    public Object deleteByIdList(@RequestParam("ids") List<Integer> ids) {
        if (ids.size() == 0) {
            return Result.success();
        }

        return Result.success(depositService.deleteByIdList(ids));
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param deposit
     * @return
     */
    // @PutMapping("/updateById")
    public Object updateById(@RequestBody Deposit deposit) {
        return Result.success(depositService.updateById(deposit));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param deposit
     * @return
     */
    // @PutMapping("/updateStaticByIdList")
    public Object updateStaticByIdList(@RequestBody Deposit deposit) {
        return Result.success(depositService.updateStaticByIdList(deposit));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param deposit
     * @return
     */
    // @PutMapping("/updateChangeByIdList")
    public Object updateChangeByIdList(@RequestBody Deposit deposit) {
        return Result.success(depositService.updateChangeByIdList(deposit));
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param deposit
     * @return
     */
    // @PutMapping("/updatePartialById")
    public Object updatePartialById(@RequestBody Deposit deposit) {
        return Result.success(depositService.updatePartialById(deposit));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param deposit
     * @return
     */
    // @PutMapping("/updateStaticPartialByIdList")
    public Object updateStaticPartialByIdList(@RequestBody Deposit deposit) {
        return Result.success(depositService.updateStaticPartialByIdList(deposit));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param deposit
     * @return
     */
    // @PutMapping("/updateChangePartialByIdList")
    public Object updateChangePartialByIdList(@RequestBody Deposit deposit) {
        return Result.success(depositService.updateChangePartialByIdList(deposit));
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     */
    // @GetMapping("/findById")
    public Object findById(Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(depositService.findById(id));
    }

    /**
     * 通过id列表查询
     * 
     * @param ids
     * @return
     */
    // @GetMapping("/findByIdList")
    public Object findByIdList(@RequestParam("ids[]") List<Integer> ids) {
        if (ids.size() == 0) {
            return Result.success();
        }

        return Result.success(depositService.findByIdList(ids));
    }

    /**
     * 通过对象查询id列表
     * 
     * @param deposit
     * @return
     */
    // @GetMapping("/findIdByDto")
    public Object findIdByDto(Deposit deposit) {
        return Result.success(depositService.findIdByDto(deposit));
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     */
    // @DeleteMapping("/clear")
    public Object clear() {
        depositService.clear();
        return Result.success();
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     * @throws IOException 
     */
    @GetMapping("/getInfo")
    @PreAuthorize("@ss.login()")
    public Object getInfo() throws IOException {
        MemberVo findDeposit = memberService.findDeposit(TokenUtil.getUserId());
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("user", findDeposit);
        hashMap.put("deposit", depositService.getInfo());
        hashMap.put("depositOrder", findDeposit.getOrderDeposit());
        return Result.success(hashMap);
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     * @throws IOException 
     */
    @GetMapping("/getInfoApp")
    @PreAuthorize("@ss.login()")
    public Object getInfoApp() throws IOException {
        MemberVo findDeposit = memberService.findDeposit(TokenUtil.getUserId());
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("user", findDeposit);
        hashMap.put("deposit", depositService.getInfo());
        hashMap.put("depositOrder", findDeposit.getOrderDeposit());
        return Result.success(hashMap);
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param deposit
     * @return
     * @throws IOException 
     */
    @PutMapping("/update")
    @PreAuthorize("@ss.hasPermi('/deposit/update')")
    public Object update(@RequestBody Deposit deposit) throws IOException {
        return Result.success(depositService.update(deposit));
    }

}